package com.ml.kafka.producer;

import com.alibaba.fastjson.JSONObject;
import com.ml.kafka.dto.KafkaMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

/**
 * @author xr-8
 * @date 2021-05-05
 * @time 19:34
 */
@Component
public class Producer {

    @Autowired
    private KafkaTemplate<String, String> kafkaTemplate;

    public void sendKafkaMessage(KafkaMessage kafkaMessage){
        kafkaTemplate.send("myTopic", JSONObject.toJSONString(kafkaMessage));
    }
}
